mirror of
https://git.osgeo.org/gitea/postgis/postgis
synced 2024-10-23 08:32:42 +00:00
Moved getMachineEndian from parser to liblwgeom.{h,c}.
Added XDR and NDR defines. Fixed all usage of them. git-svn-id: http://svn.osgeo.org/postgis/trunk@1162 b70326c6-7e19-0410-871a-916f4a2858ee
This commit is contained in:
parent
885a59ffbd
commit
db7e4ac797
|
@ -169,3 +169,13 @@ trim_trailing_zeros(char *str)
|
|||
|
||||
//lwnotice("output: %s", str);
|
||||
}
|
||||
|
||||
char getMachineEndian()
|
||||
{
|
||||
static int endian_check_int = 1; // dont modify this!!!
|
||||
|
||||
return *((char *) &endian_check_int); // 0 = big endian | xdr,
|
||||
// 1 = little endian | ndr
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -350,6 +350,8 @@ extern int pointArray_ptsize(const POINTARRAY *pa);
|
|||
|
||||
#define WKBZOFFSET 0x80000000
|
||||
#define WKBMOFFSET 0x40000000
|
||||
#define WKBSRIDFLAG 0x20000000
|
||||
#define WKBBBOXFLAG 0x10000000
|
||||
|
||||
#define TYPE_SETTYPE(c,t) ((c)=(((c)&0xF0)|(t)))
|
||||
#define TYPE_SETZM(t,z,m) ((t)=(((t)&0xCF)|((z)<<5)|((m)<<4)))
|
||||
|
@ -1030,4 +1032,9 @@ extern void lwfree(void *mem);
|
|||
/* Utilities */
|
||||
extern void trim_trailing_zeros(char *num);
|
||||
|
||||
/* Machine endianness */
|
||||
#define XDR 0
|
||||
#define NDR 1
|
||||
extern char getMachineEndian(void);
|
||||
|
||||
#endif // !defined _LIBLWGEOM_H
|
||||
|
|
|
@ -23,7 +23,7 @@
|
|||
#include "stringBuffer.h"
|
||||
|
||||
|
||||
#define DEBUG 1
|
||||
//#define DEBUG 1
|
||||
|
||||
#include "lwgeom_pg.h"
|
||||
#include "wktparse.h"
|
||||
|
@ -251,7 +251,7 @@ Datum LWGEOMFromWKB(PG_FUNCTION_ARGS)
|
|||
|
||||
size_header = sprintf(sridText,"SRID=%i;",SRID);
|
||||
//SRID text size + wkb size (+1 = NULL term)
|
||||
size_result = size_header + 2*(wkb_input->size -4) + 1;
|
||||
size_result = size_header + 2*(wkb_input->size-4) + 1;
|
||||
|
||||
wkb_srid_hexized = palloc(size_result);
|
||||
wkb_srid_hexized[0] = 0; // empty
|
||||
|
@ -312,11 +312,11 @@ Datum WKBFromLWGEOM(PG_FUNCTION_ARGS)
|
|||
if ( ! strncmp(VARDATA(type), "xdr", 3) ||
|
||||
! strncmp(VARDATA(type), "XDR", 3) )
|
||||
{
|
||||
byteorder = BIG_ENDIAN;
|
||||
byteorder = XDR;
|
||||
}
|
||||
else
|
||||
{
|
||||
byteorder = LITTLE_ENDIAN;
|
||||
byteorder = NDR;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -494,7 +494,7 @@ Datum LWGEOM_recv(PG_FUNCTION_ARGS)
|
|||
#endif
|
||||
|
||||
#ifdef DEBUG
|
||||
elog(NOTICE, "LWGEOMFromWKB returned %s", unparse_WKB(SERIALIZED_FORM(result),pg_alloc,pg_free,-1));
|
||||
elog(NOTICE, "LWGEOM_from_bytea returned %s", unparse_WKB(SERIALIZED_FORM(result),pg_alloc,pg_free,-1));
|
||||
#endif
|
||||
|
||||
|
||||
|
|
|
@ -21,16 +21,6 @@
|
|||
void set_zm(char z, char m);
|
||||
void close_parser(void);
|
||||
|
||||
#undef LITTLE_ENDIAN
|
||||
#define LITTLE_ENDIAN 1
|
||||
char getMachineEndian()
|
||||
{
|
||||
static int endian_check_int = 1; // dont modify this!!!
|
||||
|
||||
return *((char *) &endian_check_int); // 0 = big endian, 1 = little endian
|
||||
}
|
||||
|
||||
|
||||
typedef unsigned long int4;
|
||||
|
||||
typedef struct tag_tuple tuple;
|
||||
|
@ -295,7 +285,7 @@ void
|
|||
WRITE_INT4(output_state * out,int4 val)
|
||||
{
|
||||
if ( val <= 0x7f ){
|
||||
if ( getMachineEndian() == LITTLE_ENDIAN ){
|
||||
if ( getMachineEndian() == NDR ){
|
||||
val = (val<<1) | 1;
|
||||
}
|
||||
else{
|
||||
|
@ -306,7 +296,7 @@ WRITE_INT4(output_state * out,int4 val)
|
|||
the_geom.alloc_size-=3;
|
||||
}
|
||||
else{
|
||||
if ( getMachineEndian() == LITTLE_ENDIAN ){
|
||||
if ( getMachineEndian() == NDR ){
|
||||
val <<=1;
|
||||
}
|
||||
WRITE_INT4_REAL(out,val);
|
||||
|
@ -749,13 +739,9 @@ parse_wkb(const char** b)
|
|||
byte xdr = read_wkb_byte(b);
|
||||
swap_order=0;
|
||||
|
||||
if ( xdr == 0x01 ){ // wkb is in little endian
|
||||
if ( getMachineEndian() != LITTLE_ENDIAN )
|
||||
swap_order=1;
|
||||
}
|
||||
else if ( xdr == 0x00 ){ // wkb is in big endian
|
||||
if ( getMachineEndian() == LITTLE_ENDIAN )
|
||||
swap_order=1;
|
||||
if ( xdr != getMachineEndian() )
|
||||
{
|
||||
swap_order=1;
|
||||
}
|
||||
|
||||
type = read_wkb_int(b);
|
||||
|
@ -777,6 +763,12 @@ parse_wkb(const char** b)
|
|||
}
|
||||
else the_geom.hasM = 0;
|
||||
|
||||
if (type & WKBSRIDFLAG )
|
||||
{
|
||||
the_geom.hasZ = 1;
|
||||
the_geom.ndims++;
|
||||
}
|
||||
|
||||
type &=0x0f;
|
||||
|
||||
if ( the_geom.lwgi ){
|
||||
|
|
|
@ -68,7 +68,6 @@ void alloc_wkb(const char* parser);
|
|||
byte* parse_lwg(const char* wkt,allocator allocfunc,report_error errfunc);
|
||||
byte* parse_lwgi(const char* wkt,allocator allocfunc,report_error errfunc);
|
||||
char* unparse_WKT(byte* serialized, allocator alloc,freeor free);
|
||||
char* unparse_WKB(byte* serialized, allocator alloc,freeor free, unsigned int endian);
|
||||
char* unparse_WKB(byte* serialized, allocator alloc,freeor free, char endian);
|
||||
|
||||
|
||||
char getMachineEndian();
|
||||
|
|
|
@ -21,22 +21,6 @@
|
|||
|
||||
#include "liblwgeom.h"
|
||||
|
||||
static int endian_check_int = 1; // dont modify this!!!
|
||||
|
||||
#define LITTLE_ENDIAN_CHECK 1
|
||||
static unsigned int getMachineEndian()
|
||||
{
|
||||
// 0 = big endian, 1 = little endian
|
||||
if ( *((char *) &endian_check_int) )
|
||||
{
|
||||
return LITTLE_ENDIAN;
|
||||
}
|
||||
else
|
||||
{
|
||||
return BIG_ENDIAN;
|
||||
}
|
||||
}
|
||||
|
||||
//-- Typedefs ----------------------------------------------
|
||||
|
||||
typedef unsigned long int4;
|
||||
|
@ -133,7 +117,7 @@ read_int(byte** geom)
|
|||
{
|
||||
int4 ret;
|
||||
#ifdef SHRINK_INTS
|
||||
if ( getMachineEndian() == LITTLE_ENDIAN_CHECK ){
|
||||
if ( getMachineEndian() == NDR ){
|
||||
if( (**geom)& 0x01){
|
||||
ret = **geom >>1;
|
||||
(*geom)++;
|
||||
|
@ -151,7 +135,7 @@ read_int(byte** geom)
|
|||
memcpy(&ret,*geom,4);
|
||||
|
||||
#ifdef SHRINK_INTS
|
||||
if ( getMachineEndian() == LITTLE_ENDIAN_CHECK ){
|
||||
if ( getMachineEndian() == NDR ){
|
||||
ret >>= 1;
|
||||
}
|
||||
#endif
|
||||
|
@ -524,7 +508,7 @@ output_wkb(byte* geom)
|
|||
}
|
||||
|
||||
char *
|
||||
unparse_WKB(byte* serialized, allocator alloc, freeor free, unsigned int endian)
|
||||
unparse_WKB(byte* serialized, allocator alloc, freeor free, char endian)
|
||||
{
|
||||
|
||||
#ifdef DEBUG
|
||||
|
@ -540,13 +524,14 @@ unparse_WKB(byte* serialized, allocator alloc, freeor free, unsigned int endian)
|
|||
out_start = out_pos = alloc(len);
|
||||
lwgi=0;
|
||||
|
||||
if ( endian == -1 ) endian = getMachineEndian();
|
||||
|
||||
if ( endian == LITTLE_ENDIAN) endianbyte=1;
|
||||
else endianbyte=0;
|
||||
|
||||
if ( endian != getMachineEndian() ) flipbytes = 1;
|
||||
else flipbytes = 0;
|
||||
if ( endian == -1 ) {
|
||||
endianbyte = getMachineEndian();
|
||||
flipbytes = 0;
|
||||
} else {
|
||||
endianbyte = endian;
|
||||
if ( endianbyte != getMachineEndian() ) flipbytes = 1;
|
||||
else flipbytes = 0;
|
||||
}
|
||||
|
||||
output_wkb(serialized);
|
||||
ensure(1);
|
||||
|
@ -558,6 +543,11 @@ unparse_WKB(byte* serialized, allocator alloc, freeor free, unsigned int endian)
|
|||
|
||||
/******************************************************************
|
||||
* $Log$
|
||||
* Revision 1.14 2004/12/17 11:08:53 strk
|
||||
* Moved getMachineEndian from parser to liblwgeom.{h,c}.
|
||||
* Added XDR and NDR defines.
|
||||
* Fixed all usage of them.
|
||||
*
|
||||
* Revision 1.13 2004/10/25 12:27:33 strk
|
||||
* Removed useless network type includes,
|
||||
* Added param.h include for BYTE_ORDER defines under win32.
|
||||
|
|
Loading…
Reference in a new issue