Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit0249c24

Browse files
committed
More binary I/O routines.
1 parent72f311b commit0249c24

File tree

11 files changed

+584
-25
lines changed

11 files changed

+584
-25
lines changed

‎src/backend/utils/adt/cash.c

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
* workings can be found in the book "Software Solutions in C" by
1010
* Dale Schumacher, Academic Press, ISBN: 0-12-632360-7.
1111
*
12-
* $Header: /cvsroot/pgsql/src/backend/utils/adt/cash.c,v 1.57 2003/03/11 21:01:33 tgl Exp $
12+
* $Header: /cvsroot/pgsql/src/backend/utils/adt/cash.c,v 1.58 2003/05/13 18:03:07 tgl Exp $
1313
*/
1414

1515
#include"postgres.h"
@@ -19,6 +19,7 @@
1919
#include<math.h>
2020
#include<locale.h>
2121

22+
#include"libpq/pqformat.h"
2223
#include"miscadmin.h"
2324
#include"utils/builtins.h"
2425
#include"utils/cash.h"
@@ -310,6 +311,31 @@ cash_out(PG_FUNCTION_ARGS)
310311
PG_RETURN_CSTRING(result);
311312
}
312313

314+
/*
315+
*cash_recv- converts external binary format to cash
316+
*/
317+
Datum
318+
cash_recv(PG_FUNCTION_ARGS)
319+
{
320+
StringInfobuf= (StringInfo)PG_GETARG_POINTER(0);
321+
322+
PG_RETURN_CASH((Cash)pq_getmsgint(buf,sizeof(Cash)));
323+
}
324+
325+
/*
326+
*cash_send- converts cash to binary format
327+
*/
328+
Datum
329+
cash_send(PG_FUNCTION_ARGS)
330+
{
331+
Casharg1=PG_GETARG_CASH(0);
332+
StringInfoDatabuf;
333+
334+
pq_begintypsend(&buf);
335+
pq_sendint(&buf,arg1,sizeof(Cash));
336+
PG_RETURN_BYTEA_P(pq_endtypsend(&buf));
337+
}
338+
313339

314340
Datum
315341
cash_eq(PG_FUNCTION_ARGS)

‎src/backend/utils/adt/geo_ops.c

Lines changed: 266 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/utils/adt/geo_ops.c,v 1.76 2003/05/09 21:19:49 tgl Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/utils/adt/geo_ops.c,v 1.77 2003/05/13 18:03:07 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -409,6 +409,58 @@ box_out(PG_FUNCTION_ARGS)
409409
PG_RETURN_CSTRING(path_encode(-1,2,&(box->high)));
410410
}
411411

412+
/*
413+
*box_recv- converts external binary format to box
414+
*/
415+
Datum
416+
box_recv(PG_FUNCTION_ARGS)
417+
{
418+
StringInfobuf= (StringInfo)PG_GETARG_POINTER(0);
419+
BOX*box;
420+
doublex,
421+
y;
422+
423+
box= (BOX*)palloc(sizeof(BOX));
424+
425+
box->high.x=pq_getmsgfloat8(buf);
426+
box->high.y=pq_getmsgfloat8(buf);
427+
box->low.x=pq_getmsgfloat8(buf);
428+
box->low.y=pq_getmsgfloat8(buf);
429+
430+
/* reorder corners if necessary... */
431+
if (box->high.x<box->low.x)
432+
{
433+
x=box->high.x;
434+
box->high.x=box->low.x;
435+
box->low.x=x;
436+
}
437+
if (box->high.y<box->low.y)
438+
{
439+
y=box->high.y;
440+
box->high.y=box->low.y;
441+
box->low.y=y;
442+
}
443+
444+
PG_RETURN_BOX_P(box);
445+
}
446+
447+
/*
448+
*box_send- converts box to binary format
449+
*/
450+
Datum
451+
box_send(PG_FUNCTION_ARGS)
452+
{
453+
BOX*box=PG_GETARG_BOX_P(0);
454+
StringInfoDatabuf;
455+
456+
pq_begintypsend(&buf);
457+
pq_sendfloat8(&buf,box->high.x);
458+
pq_sendfloat8(&buf,box->high.y);
459+
pq_sendfloat8(&buf,box->low.x);
460+
pq_sendfloat8(&buf,box->low.y);
461+
PG_RETURN_BYTEA_P(pq_endtypsend(&buf));
462+
}
463+
412464

413465
/*box_construct-fill in a new box.
414466
*/
@@ -915,6 +967,26 @@ line_out(PG_FUNCTION_ARGS)
915967
PG_RETURN_CSTRING(result);
916968
}
917969

970+
/*
971+
*line_recv- converts external binary format to line
972+
*/
973+
Datum
974+
line_recv(PG_FUNCTION_ARGS)
975+
{
976+
elog(ERROR,"line not yet implemented");
977+
return0;
978+
}
979+
980+
/*
981+
*line_send- converts line to binary format
982+
*/
983+
Datum
984+
line_send(PG_FUNCTION_ARGS)
985+
{
986+
elog(ERROR,"line not yet implemented");
987+
return0;
988+
}
989+
918990

919991
/*----------------------------------------------------------
920992
*Conversion routines from one line formula to internal.
@@ -1271,6 +1343,64 @@ path_out(PG_FUNCTION_ARGS)
12711343
PG_RETURN_CSTRING(path_encode(path->closed,path->npts,path->p));
12721344
}
12731345

1346+
/*
1347+
*path_recv- converts external binary format to path
1348+
*
1349+
* External representation is closed flag (a boolean byte), int32 number
1350+
* of points, and the points.
1351+
*/
1352+
Datum
1353+
path_recv(PG_FUNCTION_ARGS)
1354+
{
1355+
StringInfobuf= (StringInfo)PG_GETARG_POINTER(0);
1356+
PATH*path;
1357+
intclosed;
1358+
int32npts;
1359+
int32i;
1360+
intsize;
1361+
1362+
closed=pq_getmsgbyte(buf);
1363+
npts=pq_getmsgint(buf,sizeof(int32));
1364+
if (npts<0||npts >= (int32) (INT_MAX /sizeof(Point)))
1365+
elog(ERROR,"Invalid number of points in external path");
1366+
1367+
size= offsetof(PATH,p[0])+sizeof(path->p[0])*npts;
1368+
path= (PATH*)palloc(size);
1369+
1370+
path->size=size;
1371+
path->npts=npts;
1372+
path->closed= (closed ?1 :0);
1373+
1374+
for (i=0;i<npts;i++)
1375+
{
1376+
path->p[i].x=pq_getmsgfloat8(buf);
1377+
path->p[i].y=pq_getmsgfloat8(buf);
1378+
}
1379+
1380+
PG_RETURN_PATH_P(path);
1381+
}
1382+
1383+
/*
1384+
*path_send- converts path to binary format
1385+
*/
1386+
Datum
1387+
path_send(PG_FUNCTION_ARGS)
1388+
{
1389+
PATH*path=PG_GETARG_PATH_P(0);
1390+
StringInfoDatabuf;
1391+
int32i;
1392+
1393+
pq_begintypsend(&buf);
1394+
pq_sendbyte(&buf,path->closed ?1 :0);
1395+
pq_sendint(&buf,path->npts,sizeof(int32));
1396+
for (i=0;i<path->npts;i++)
1397+
{
1398+
pq_sendfloat8(&buf,path->p[i].x);
1399+
pq_sendfloat8(&buf,path->p[i].y);
1400+
}
1401+
PG_RETURN_BYTEA_P(pq_endtypsend(&buf));
1402+
}
1403+
12741404

12751405
/*----------------------------------------------------------
12761406
*Relational operators.
@@ -1815,6 +1945,46 @@ lseg_out(PG_FUNCTION_ARGS)
18151945
PG_RETURN_CSTRING(path_encode(FALSE,2, (Point*)&(ls->p[0])));
18161946
}
18171947

1948+
/*
1949+
*lseg_recv- converts external binary format to lseg
1950+
*/
1951+
Datum
1952+
lseg_recv(PG_FUNCTION_ARGS)
1953+
{
1954+
StringInfobuf= (StringInfo)PG_GETARG_POINTER(0);
1955+
LSEG*lseg;
1956+
1957+
lseg= (LSEG*)palloc(sizeof(LSEG));
1958+
1959+
lseg->p[0].x=pq_getmsgfloat8(buf);
1960+
lseg->p[0].y=pq_getmsgfloat8(buf);
1961+
lseg->p[1].x=pq_getmsgfloat8(buf);
1962+
lseg->p[1].y=pq_getmsgfloat8(buf);
1963+
1964+
#ifdefNOT_USED
1965+
lseg->m=point_sl(&lseg->p[0],&lseg->p[1]);
1966+
#endif
1967+
1968+
PG_RETURN_LSEG_P(lseg);
1969+
}
1970+
1971+
/*
1972+
*lseg_send- converts lseg to binary format
1973+
*/
1974+
Datum
1975+
lseg_send(PG_FUNCTION_ARGS)
1976+
{
1977+
LSEG*ls=PG_GETARG_LSEG_P(0);
1978+
StringInfoDatabuf;
1979+
1980+
pq_begintypsend(&buf);
1981+
pq_sendfloat8(&buf,ls->p[0].x);
1982+
pq_sendfloat8(&buf,ls->p[0].y);
1983+
pq_sendfloat8(&buf,ls->p[1].x);
1984+
pq_sendfloat8(&buf,ls->p[1].y);
1985+
PG_RETURN_BYTEA_P(pq_endtypsend(&buf));
1986+
}
1987+
18181988

18191989
/* lseg_construct -
18201990
*form a LSEG from two Points.
@@ -3186,6 +3356,64 @@ poly_out(PG_FUNCTION_ARGS)
31863356
PG_RETURN_CSTRING(path_encode(TRUE,poly->npts,poly->p));
31873357
}
31883358

3359+
/*
3360+
*poly_recv- converts external binary format to polygon
3361+
*
3362+
* External representation is int32 number of points, and the points.
3363+
* We recompute the bounding box on read, instead of trusting it to
3364+
* be valid. (Checking it would take just as long, so may as well
3365+
* omit it from external representation.)
3366+
*/
3367+
Datum
3368+
poly_recv(PG_FUNCTION_ARGS)
3369+
{
3370+
StringInfobuf= (StringInfo)PG_GETARG_POINTER(0);
3371+
POLYGON*poly;
3372+
int32npts;
3373+
int32i;
3374+
intsize;
3375+
3376+
npts=pq_getmsgint(buf,sizeof(int32));
3377+
if (npts<0||npts >= (int32) ((INT_MAX- offsetof(POLYGON,p[0])) /sizeof(Point)))
3378+
elog(ERROR,"Invalid number of points in external polygon");
3379+
3380+
size= offsetof(POLYGON,p[0])+sizeof(poly->p[0])*npts;
3381+
poly= (POLYGON*)palloc0(size);/* zero any holes */
3382+
3383+
poly->size=size;
3384+
poly->npts=npts;
3385+
3386+
for (i=0;i<npts;i++)
3387+
{
3388+
poly->p[i].x=pq_getmsgfloat8(buf);
3389+
poly->p[i].y=pq_getmsgfloat8(buf);
3390+
}
3391+
3392+
make_bound_box(poly);
3393+
3394+
PG_RETURN_POLYGON_P(poly);
3395+
}
3396+
3397+
/*
3398+
*poly_send- converts polygon to binary format
3399+
*/
3400+
Datum
3401+
poly_send(PG_FUNCTION_ARGS)
3402+
{
3403+
POLYGON*poly=PG_GETARG_POLYGON_P(0);
3404+
StringInfoDatabuf;
3405+
int32i;
3406+
3407+
pq_begintypsend(&buf);
3408+
pq_sendint(&buf,poly->npts,sizeof(int32));
3409+
for (i=0;i<poly->npts;i++)
3410+
{
3411+
pq_sendfloat8(&buf,poly->p[i].x);
3412+
pq_sendfloat8(&buf,poly->p[i].y);
3413+
}
3414+
PG_RETURN_BYTEA_P(pq_endtypsend(&buf));
3415+
}
3416+
31893417

31903418
/*-------------------------------------------------------
31913419
* Is polygon A strictly left of polygon B? i.e. is
@@ -4001,6 +4229,43 @@ circle_out(PG_FUNCTION_ARGS)
40014229
PG_RETURN_CSTRING(result);
40024230
}
40034231

4232+
/*
4233+
*circle_recv- converts external binary format to circle
4234+
*/
4235+
Datum
4236+
circle_recv(PG_FUNCTION_ARGS)
4237+
{
4238+
StringInfobuf= (StringInfo)PG_GETARG_POINTER(0);
4239+
CIRCLE*circle;
4240+
4241+
circle= (CIRCLE*)palloc(sizeof(CIRCLE));
4242+
4243+
circle->center.x=pq_getmsgfloat8(buf);
4244+
circle->center.y=pq_getmsgfloat8(buf);
4245+
circle->radius=pq_getmsgfloat8(buf);
4246+
4247+
if (circle->radius<0)
4248+
elog(ERROR,"Invalid radius in external circle");
4249+
4250+
PG_RETURN_CIRCLE_P(circle);
4251+
}
4252+
4253+
/*
4254+
*circle_send- converts circle to binary format
4255+
*/
4256+
Datum
4257+
circle_send(PG_FUNCTION_ARGS)
4258+
{
4259+
CIRCLE*circle=PG_GETARG_CIRCLE_P(0);
4260+
StringInfoDatabuf;
4261+
4262+
pq_begintypsend(&buf);
4263+
pq_sendfloat8(&buf,circle->center.x);
4264+
pq_sendfloat8(&buf,circle->center.y);
4265+
pq_sendfloat8(&buf,circle->radius);
4266+
PG_RETURN_BYTEA_P(pq_endtypsend(&buf));
4267+
}
4268+
40044269

40054270
/*----------------------------------------------------------
40064271
*Relational operators for CIRCLEs.

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp