www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - MemoryConduit

reply Alberto <reda zioale.it> writes:
I can write xml on buffer/file without  problems, but I have some little
problem parsing an xml from a buffer.
This is part of the sax example:

void readerTest3()
{
	ISAXReader!(T) reader = new TeqXMLReader!(T)(256);
	FileConduit file = new FileConduit("sample-32BE.xml",
FileConduit.ReadExisting);
	MyOutputHandler handler = new MyOutputHandler();
	reader.parse(file, handler, Encoding.UTF_32);
}

I read the sax source:
/**
   All SAX parsers must implement this interface.
 */
interface ISAXReader(T=char) {
  	/**
	   Tells the parser to begin processing a document

	   Params:
	   	source =	The IConduit that the parser should draw xml content from
		handler =	The client interface who's methods the parser should call
		encoding =	If the client knows it, tell the parser the text encoding
of the incoming XML.
				If not specified, the parser will guess, and failing that assume
UTF8N.  The
				enum for these types is in mango.convert.Unicode.
	 */
	public void parse(IConduit source, ISAXHandler!(T) handler, Encoding
encoding=Encoding.Unknown);
}

I must pass a conduit, ok.
I have tried to use MemoryConduit (I suppose that is the right way to do
what I want) but without success, something like:

char[] msg = "blabla";
char[] xml;
auto mc = new MemoryConduit();
auto write = new Writer (mc);
auto read = new Reader (mc);
write (msg);
xml.length = msg.length;
read (xml);
Stdout(xml);
mc.close();

this give me:
end-of-file whilst reading

I can't use the method writer because is not accessible, so how can I
use MemoryConduit?
Feb 13 2007
next sibling parent reply kris <foo bar.com> writes:
Alberto wrote:
 I can write xml on buffer/file without  problems, but I have some little
 problem parsing an xml from a buffer.
 This is part of the sax example:
 
 void readerTest3()
 {
 	ISAXReader!(T) reader = new TeqXMLReader!(T)(256);
 	FileConduit file = new FileConduit("sample-32BE.xml",
 FileConduit.ReadExisting);
 	MyOutputHandler handler = new MyOutputHandler();
 	reader.parse(file, handler, Encoding.UTF_32);
 }
 
 I read the sax source:
 /**
    All SAX parsers must implement this interface.
  */
 interface ISAXReader(T=char) {
   	/**
 	   Tells the parser to begin processing a document
 
 	   Params:
 	   	source =	The IConduit that the parser should draw xml content from
 		handler =	The client interface who's methods the parser should call
 		encoding =	If the client knows it, tell the parser the text encoding
 of the incoming XML.
 				If not specified, the parser will guess, and failing that assume
 UTF8N.  The
 				enum for these types is in mango.convert.Unicode.
 	 */
 	public void parse(IConduit source, ISAXHandler!(T) handler, Encoding
 encoding=Encoding.Unknown);
 }
 
 I must pass a conduit, ok.
 I have tried to use MemoryConduit (I suppose that is the right way to do
 what I want) but without success, something like:
 
 char[] msg = "blabla";
 char[] xml;
 auto mc = new MemoryConduit();
 auto write = new Writer (mc);
 auto read = new Reader (mc);
 write (msg);
 xml.length = msg.length;
 read (xml);
 Stdout(xml);
 mc.close();
 
 this give me:
 end-of-file whilst reading
 
 I can't use the method writer because is not accessible, so how can I
 use MemoryConduit?

It's not quite clear what you wish to do, but I'll have a go? First, it's worth cleaning up a bit using "auto": void readerTest3() { auto handler = new MyOutputHandler; auto reader = new TeqXMLReader!(T)(256); auto file = new FileConduit ("sample-32BE.xml"); reader.parse (file, handler, Encoding.UTF_32); } Now the questions: 1) why do you require MemoryConduit? Have you constructed some in-memory XML for parsing? 2) it's not clear why you're using protocols for this (Reader/Writer) when you can use mc.write(void[]) and/or mc.read(void[]) 3) is there a version of reader.parse() that accepts a Buffer instance instead? If not, then there probably ought to be (since it would save you some effort).
Feb 13 2007
next sibling parent reply Alberto <reda zioale.it> writes:
 1) why do you require MemoryConduit? Have you constructed some in-memory
 XML for parsing?

servlet of my HTTP server (I use mango) read the xml and must parse it.
 2) it's not clear why you're using protocols for this (Reader/Writer)
 when you can use mc.write(void[]) and/or mc.read(void[])

that I have downloaded the last version from svn, mc.write(void[]) works. With that my problem with MemoryConduit is solved. But now tango give me an error when I include tango.io.FileConduit. c:\dmd\tango\tango\io\FileProxy.obj(FileProxy) Error 42: Symbol Undefined _D12TypeInfo_AAa6__initZ
 
 3) is there a version of reader.parse() that accepts a Buffer instance
 instead? If not, then there probably ought to be (since it would save
 you some effort).

Feb 13 2007
parent reply kris <foo bar.com> writes:
Alberto wrote:
1) why do you require MemoryConduit? Have you constructed some in-memory
XML for parsing?

yes, I must transfer xml file using POST method of HTTP (text/xml). So a servlet of my HTTP server (I use mango) read the xml and must parse it.
2) it's not clear why you're using protocols for this (Reader/Writer)
when you can use mc.write(void[]) and/or mc.read(void[])

because they didn't work for me, (some strange error on compile), now that I have downloaded the last version from svn, mc.write(void[]) works. With that my problem with MemoryConduit is solved. But now tango give me an error when I include tango.io.FileConduit. c:\dmd\tango\tango\io\FileProxy.obj(FileProxy) Error 42: Symbol Undefined _D12TypeInfo_AAa6__initZ

What tool are you using to build your project?
Feb 13 2007
parent reply Alberto <reda zioale.it> writes:
 What tool are you using to build your project?

Of course I'm using lastest tango+mango. io 1676 2 hours kris: removed FileProxy? dependency from FileConduit?; was just overhead Ater the last update of tango all works. Thanks.
Feb 13 2007
parent reply kris <foo bar.com> writes:
Alberto wrote:
What tool are you using to build your project?

I'm using build (bud) under windows (the project must works on windows :\) Of course I'm using lastest tango+mango. io 1676 2 hours kris: removed FileProxy? dependency from FileConduit?; was just overhead Ater the last update of tango all works. Thanks.

Yep, I removed that as simply being unnecessary coupling. But that should not have affected your build in any legitimate manner. Everyone else has been building and linking these modules for ages and not run into a problem. I'd like to get to the bottom of it ... Would imagine you'll have some difficulty building the examples?
Feb 13 2007
parent Alberto <reda zioale.it> writes:
 Would imagine you'll have some difficulty building the examples?

with the build-all.bat I have some problem. for example, if I did something like (cutted from build.all): C:\dmd\tango\example> dmd conduits\composite.d ..\tango\io\protocol\Reader.d ..\tango\io\Buffer.d ..\tango\io\model\IBuffer.d ..\tango\io\model\IConduit.d ..\tango\io\protocol\model\IReader.d ..\tango\io\protocol\model\IProtocol.d ..\tango\io\protocol\Writer.d ..\tango\io\FileConst.d ..\tango\io\protocol\model\IWriter.d ..\tango\io\FileConduit.d ..\tango\sys\Common.d ..\tango\io\FileProxy.d ..\tango\io\FilePath.d ..\tango\text\convert\Utf.d ..\tango\io\DeviceConduit.d ..\tango\io\Conduit.d -I.. -op I get: ..\tango\io\FileProxy.obj(FileProxy) Error 42: Symbol Undefined _D5tango4util4time3Utc3Utc7convertFS5tango3sys5win325Types8FIL ETIMEZE5tango4core4Type4Time --- errorlevel 1 The same happens with system\argparser.d and all other conduits examples.
Feb 13 2007
prev sibling parent John Reimer <terminal.node gmail.com> writes:
On Wed, 14 Feb 2007 01:40:26 +0100, Alberto wrote:

 Would imagine you'll have some difficulty building the examples?

with the build-all.bat I have some problem. for example, if I did something like (cutted from build.all): C:\dmd\tango\example> dmd conduits\composite.d ..\tango\io\protocol\Reader.d ..\tango\io\Buffer.d ..\tango\io\model\IBuffer.d ..\tango\io\model\IConduit.d ..\tango\io\protocol\model\IReader.d ..\tango\io\protocol\model\IProtocol.d ..\tango\io\protocol\Writer.d ..\tango\io\FileConst.d ..\tango\io\protocol\model\IWriter.d ..\tango\io\FileConduit.d ..\tango\sys\Common.d ..\tango\io\FileProxy.d ..\tango\io\FilePath.d ..\tango\text\convert\Utf.d ..\tango\io\DeviceConduit.d ..\tango\io\Conduit.d -I.. -op I get: ..\tango\io\FileProxy.obj(FileProxy) Error 42: Symbol Undefined _D5tango4util4time3Utc3Utc7convertFS5tango3sys5win325Types8FIL ETIMEZE5tango4core4Type4Time --- errorlevel 1 The same happens with system\argparser.d and all other conduits examples.

I actually think I'll have to remove the build-all.bat eventually because, if you are using the svn latest code, the code changes end up rendering build-all quite useless. It the meantime, if you use windows, you can use the jake version of it (jake-all.bat) and it sould succeed. rebuild also appears to work well. I haven't tried bud, but it will probably work too. -JJR
Feb 14 2007
prev sibling next sibling parent kris <foo bar.com> writes:
Alberto wrote:
 this give me:
 end-of-file whilst reading

The reason for the Eof is that you need to flush the output first. In Tango pretty much all IO above the level of a Conduit is buffered, so you'd need to do this: # write (data) (); or # write (data).flush;
Feb 13 2007
prev sibling parent John Demme <me teqdruid.com> writes:
Alberto wrote:

 I can write xml on buffer/file without  problems, but I have some little
 problem parsing an xml from a buffer.
 This is part of the sax example:
 
 void readerTest3()
 {
 ISAXReader!(T) reader = new TeqXMLReader!(T)(256);
 FileConduit file = new FileConduit("sample-32BE.xml",
 FileConduit.ReadExisting);
 MyOutputHandler handler = new MyOutputHandler();
 reader.parse(file, handler, Encoding.UTF_32);
 }
 
 I read the sax source:
 /**
    All SAX parsers must implement this interface.
  */
 interface ISAXReader(T=char) {
   /**
 Tells the parser to begin processing a document
 
 Params:
 source =      The IConduit that the parser should draw xml content from
 handler =     The client interface who's methods the parser should call
 encoding =    If the client knows it, tell the parser the text encoding
 of the incoming XML.
 If not specified, the parser will guess, and failing that assume
 UTF8N.  The
 enum for these types is in mango.convert.Unicode.
 */
 public void parse(IConduit source, ISAXHandler!(T) handler, Encoding
 encoding=Encoding.Unknown);
 }
 
 I must pass a conduit, ok.
 I have tried to use MemoryConduit (I suppose that is the right way to do
 what I want) but without success, something like:
 
 char[] msg = "blabla";
 char[] xml;
 auto mc = new MemoryConduit();
 auto write = new Writer (mc);
 auto read = new Reader (mc);
 write (msg);
 xml.length = msg.length;
 read (xml);
 Stdout(xml);
 mc.close();
 
 this give me:
 end-of-file whilst reading
 
 I can't use the method writer because is not accessible, so how can I
 use MemoryConduit?

I just added support today for reader.parse(IBuffer). Have fun :) -- ~John Demme me teqdruid.com http://www.teqdruid.com/
Feb 13 2007