cniElementAsBitstream

지정된 요소의 비트스트림 표현을 가져옵니다. 요소와 연관된 구문 분석기는 요소 및 모든 하위 요소를 직렬화합니다. 결과는 호출자가 할당한 메모리에 복사됩니다. 지정된 모든 옵션이 원본 비트스트림 옵션과 일치하며(예: MQInput 노드가 WebSphere MQ 큐에서 읽은 비트스트림의 경우) 원본 비트스트림을 수신한 이후 메시지가 수정되지 않은 특수한 경우, 이 원본 비트스트림은 사용자가 할당한 메모리로 복사됩니다. 이 경우, 메시지를 구문 분석하고 다시 직렬화하기 위해 구문 분석기가 필요하지 않습니다.

비트스트림을 생성하는 데 사용되는 알고리즘은 사용할 구문 분석기와 지정된 옵션에 따라 다릅니다. 모든 구문 분석기는 다음 모드를 지원합니다.
  • RootBitStream, 이 모드에서 비트스트림 생성 알고리즘은 출력 노드에 사용되는 알고리즘과 같습니다. 이 모드에서는 가리키는 요소가 적절한 구조를 가진 서브트리의 맨 위에 있는 경우에만 유용한 결과를 얻습니다.
  • EmbeddedBitStream, 이 모드에서 비트스트림 생성 알고리즘은 출력 노드에 사용되는 알고리즘과 같을 뿐 아니라 명시적으로 지정되지 않은 경우 출력 노드와 같은 방식으로 다음을 판별합니다(다음이 헤더를 나타낸다는 가정 하에 요소의 이전 동위를 검색하여 판별함).
    • 인코딩
    • CCSID
    • 메시지 세트
    • 메시지 유형
    • Message format

    그러므로 이러한 등록 정보를 판별하는 알고리즘은 기본적으로 ESQL BITSTREAM 함수에 사용되는 알고리즘과 같습니다.

일부 구문 분석기는 다른 모드인 FolderBitStream도 지원하며 이 모드에서는 가리키는 필드가 폴더를 나타낸다는 전제 하에 하위 트리에 대해 의미있는 비트스트림이 생성됩니다.

구문

CciSize cniElementAsBitstream(
  int*                       returnCode,
  CciElement*                element,
  const struct CciByteArray* value,
  CciChar*                   messageType,
  CciChar*                   messageSet,
  CciChar*                   messageFormat,
  int                        encoding,
  int                        ccsid,
  int                        options);

매개변수

returnCode
함수의 리턴 코드(출력). 널(null) 포인터는 노드가 오류를 처리하지 않음을 의미합니다. 입력이 널(null)이 아닌 경우, 출력은 호출 성공 상태를 의미합니다. 이 호출 실행 중 전달된 모든 예외는 플로우의 다음 업스트림 노드에 다시 전달됩니다. 예외에 대한 자세한 내용은 cciGetLastExceptionData를 호출하십시오.
가능한 리턴 코드는 다음과 같습니다.
  • CCI_SUCCESS
  • CCI_EXCEPTION
  • CCI_INV_ELEMENT_OBJECT
  • CCI_INV_DATA_POINTER
  • CCI_INV_DATA_BUFLEN
  • CCI_INV_BUFFER_TOO_SMALL
element
직렬화할 구문 요소(입력).
직렬화할 구문 요소(입력). 메시지 루트의 마지막 하위 요소여야 합니다.
value
호출자가 할당한 메모리 영역을 가리키는 포인터 및 이 메모리의 CciBytes 단위 크기가 포함된 CciByteArray 구조를 가리키는 포인터(출력).
messageType
요소 트리로부터 비트스트림을 작성하는 데 사용되는 메시지 유형 정의(입력). 널(null) 포인터는 이 매개변수를 무시함을 의미합니다. 또한, 요소와 연관된 구문 분석기에서 이 값을 필요로 하지 않을 경우, 가령 그 구문 분석기가 일반 XML 구문 분석기인 경우, 매개변수는 무시됩니다.
messageSet
요소 트리로부터 비트스트림을 작성하는 데 사용되는 메시지 세트 정의(입력). 널(null) 포인터는 이 매개변수를 무시함을 의미합니다. 또한, 요소와 연관된 구문 분석기에서 이 값을 필요로 하지 않을 경우, 가령 그 구문 분석기가 일반 XML 구문 분석기인 경우, 매개변수는 무시됩니다.
messageFormat
요소 트리로부터 비트스트림을 작성하는 데 사용되는 형식(입력). 널(null) 포인터는 이 매개변수를 무시함을 의미합니다. 또한, 요소와 연관된 구문 분석기에서 이 값을 필요로 하지 않을 경우, 가령 그 구문 분석기가 일반 XML 구문 분석기인 경우, 매개변수는 무시됩니다.
encoding
비트스트림을 쓸 때 사용할 인코딩(입력). 이 매개변수는 필수입니다. 큐 관리자의 인코딩을 사용해야 함을 나타내려면 0 값을 지정하면 됩니다.
ccsid
비트스트림을 쓸 때 사용할 코딩 문자 세트 ID(입력). 이 매개변수는 필수입니다. 큐 관리자의 CCSID를 사용해야 함을 나타내려면 0 값을 지정하면 됩니다. CCSID -1은 요소 및 하위 요소별로 지정되는 필드로 구성된 서브트리에 있는 CCSID 정보를 사용하여 비트스트림이 생성됨을 나타냅니다. 현재 이 옵션을 지원하는 구문 분석기는 없습니다.
options
사용할 비트스트림 생성 모드를 지정하는 정수 값. 다음 값 중 하나가 될 수 있습니다.
  • CCI_BITSTREAM_OPTIONS_ROOT
  • CCI_BITSTREAM_OPTIONS_EMBEDDED
  • CCI_BITSTREAM_OPTIONS_FOLDER

리턴 값

  • 함수가 정상적으로 실행되면, 비트스트림을 보유하기 위한 정확한 메모리 크기가 리턴됩니다.
  • 호출자가 할당한 메모리가 충분하지 않은 경우, returnCode는 CCI_BUFFER_TOO_SMALL로 설정됩니다.
  • 실행 중 예외가 발생할 경우, returnCode는 CCI_EXCEPTION으로 설정됩니다.

다음 예에서는 옵션 매개변수를 사용하여 메시지 트리의 다른 부분에 대한 비트스트림을 생성하는 방법을 보여줍니다.

이 코드는 샘플 Transform 노드의 _evaluate 함수에 복사할 수 있습니다. 다음과 같은 입력 메시지의 경우
      MQMD
RFH2
<test><data><stuff>things</stuff></data></test>
노드는 세 개의 메시지를 전달하는 데 그 중 하나는 BLOB 도메인에 입력 메시지의 사본이 포함되어 있습니다. 다른 메시지는 BLOB 도메인에 입력 RFH2의 사본을 메시지 본문으로 포함하고 있습니다. 또다른 메시지는 BLOB 도메인에 <data></data> 폴더를 메시지 본문으로 포함하고 있습니다.
CciMessage*          outMsg[3];
    CciTerminal* terminalObject;
  CciElement*          bodyChild;
  CciElement*          inRootElement;
  CciElement*          inSourceElement[3];
  CciElement*          outRootElement;
  CciElement*          outBlobElement;
  CciElement*          outBody;
  struct CciByteArray  bitstream[3];
  int                  bitstreamOptions[3];
  int                  retvalue;
    int                rc = 0;
  int                  loopCount;
  CCI_EXCEPTION_ST     exception_st = {CCI_EXCEPTION_ST_DEFAULT};
  const CciChar*       constBLOBParserName  =
                 cciString("NONE",BIP_DEF_COMP_CCSID);
  const CciChar*       constBLOBElementName = 
                 cciString("BLOB",BIP_DEF_COMP_CCSID);
  const CciChar*       constEmptyString     =                     
                 cciString("",BIP_DEF_COMP_CCSID);

  /*build up and propagate 3 output messages*/
  /*first message has bit stream for input message body*/
  /*second message has bit stream for input RFH2*/
  /*third message has bit stream for sub element from input message*/

  /* Get the root element of the input message */
  inRootElement=cniRootElement(&rc, message);
  /*CCI_CHECK_RC();*/
  checkRC(rc);

  /*set up the array of source elements and bitstream options*/

  /*message body*/
  inSourceElement[0] =  cniLastChild(&rc,inRootElement);
  checkRC(rc);

  /*This is the root of the message body so we use RootBitStream mode*/
  bitstreamOptions[0] = CCI_BITSTREAM_OPTIONS_ROOT;

  
  /*last header*/
  inSourceElement[1] = cniPreviousSibling(&rc,inSourceElement[0]);
  checkRC(rc);

  /*This is the root of the RFH2 so we use RootBitStream mode*/
  bitstreamOptions[1] = CCI_BITSTREAM_OPTIONS_ROOT;

  
  /*body.FIRST(first child of message body) */
  inSourceElement[2] = cniFirstChild(&rc,inSourceElement[0]);
  checkRC(rc);
  
  /*body.FIRST.FIRST */
  inSourceElement[2] = cniFirstChild(&rc,inSourceElement[2]);
  checkRC(rc);

  /*This is a sub tree within the message body so we use FolderBitStream mode*/
  bitstreamOptions[2] = CCI_BITSTREAM_OPTIONS_FOLDER;

  
  for (loopCount=0;loopCount<3;loopCount++) {
    int bufLength;

    /* Create new message for output */
    outMsg[loopCount] = cniCreateMessage(&rc, cniGetMessageContext(&rc, message));
    checkRC(rc);

    /* Get the root element of the output message */
    outRootElement = cniRootElement(&rc, outMsg[loopCount]);
    checkRC(rc);

    /* Copy the contents of the input message to the output message */
      cniCopyElementTree(&rc, inRootElement, outRootElement);
    checkRC(rc);

    /* Get the last child of root (ie the body)  */
      bodyChild = cniLastChild(&rc, outRootElement);
    checkRC(rc);

    /*throw away the message body which was copied from the input message*/
    cniDetach(&rc,
              bodyChild);
    checkRC(rc);

    /*create the new output message body in the BLOB domain*/
    outBody = cniCreateElementAsLastChildUsingParser(&rc,
                                                                                                             outRootElement,
                                           constBLOBParserName);
    checkRC(rc);

    /*create the BLOB element*/
    outBlobElement = cniCreateElementAsLastChild(&rc,
                                outBody);
    checkRC(rc);

    cniSetElementName(&rc,
                      outBlobElement,
                      constBLOBElementName);
    checkRC(rc);
    
    /*Set the value of the blob element by obtaining the bit stream for the
    */
    bitstream[loopCount].size=512;
    bitstream[loopCount].pointer=(CciByte*)malloc(sizeof(CciByte) * 512);
    
    bufLength = cniElementAsBitstream(&rc,
                          inSourceElement[loopCount],
                          &bitstream[loopCount],
                          constEmptyString,/*assume XML message so no interest in*/
                          constEmptyString,/* type, set or format*/
                          constEmptyString,
                          0,/*Use Queue Manager CCSID & Encoding*/
                          0,
                          bitstreamOptions[loopCount]);
    

    if (rc==CCI_BUFFER_TOO_SMALL) {
        free(bitstream[loopCount].pointer);
        bitstream[loopCount].size=bufLength;
        bitstream[loopCount].pointer=(CciByte*)malloc(sizeof(CciByte) * bitstream[loopCount].size);

        bufLength = cniElementAsBitstream(&rc,
                          inSourceElement[loopCount],
                          &bitstream[loopCount],
                          constEmptyString,/*assume XML message so no interest in*/
                          constEmptyString,/* type, set or format*/
                          constEmptyString,
                          0,/*Use Queue Manager CCSID & Encoding*/
                          0,
                          bitstreamOptions[loopCount]);      
    }
    checkRC(rc);
    bitstream[loopCount].size=bufLength;
    
    cniSetElementByteArrayValue(&rc,
                                outBlobElement,
                                &bitstream[loopCount]);
    checkRC(rc);
  }

  /* Get handle of output terminal */
  terminalObject = getOutputTerminalHandle( (NODE_CONTEXT_ST *)context,
                                            (CciChar*)constOut);

  /* If the terminal exists and is attached, propagate to it */
    if (terminalObject) {
        if (cniIsTerminalAttached(&rc, terminalObject)) {
      /* As this is a new, and changed message, it should be finalized... */
      cniFinalize(&rc, outMsg[0], CCI_FINALIZE_NONE);
      cniFinalize(&rc, outMsg[1], CCI_FINALIZE_NONE);
      cniFinalize(&rc, outMsg[2], CCI_FINALIZE_NONE);
      retvalue = cniPropagate(&rc, terminalObject, destinationList, exceptionList, outMsg[0]);
      retvalue = cniPropagate(&rc, terminalObject, destinationList, exceptionList, outMsg[1]);
      retvalue = cniPropagate(&rc, terminalObject, destinationList, exceptionList, outMsg[2]);
      if (retvalue == CCI_FAILURE) {
         if (rc == CCI_EXCEPTION) {
          			/* Get details of the exception */
                memset(&exception_st, 0, sizeof(exception_st));
                    cciGetLastExceptionData(&rc, &exception_st);

          /* Any local error handling may go here */

          /* Ensure message is deleted prior to return/throw */
          cniDeleteMessage(0, outMsg[0]);
          cniDeleteMessage(0, outMsg[1]);
          cniDeleteMessage(0, outMsg[2]);

          /* We must "rethrow" the exception; note this does not return */
                cciRethrowLastException(&rc);
        }
        else {

          /* Some other error...the plugin might choose to log it using the CciLog() */
          /* utility function                                                        */

        }
      }
      else {
      }
    }
  }
  else {
    /* Terminal did not exist...severe internal error. 플러그인은 cciLog() 유틸리티 */
    /* log an error here using the cciLog() utility function.                 */
  }

  /* Delete the messages we created now we have finished with them */
  cniDeleteMessage(0, outMsg[0]);
  cniDeleteMessage(0, outMsg[1]);
  cniDeleteMessage(0, outMsg[2]);

  free((void*) constBLOBParserName);
  free((void*) constBLOBElementName);
  free((void*) constEmptyString);
    return;
주의사항 | 등록상표 | 다운로드 | 라이브러리 | 지원 | 피드백
Copyright IBM Corporation 1999, 2006 마지막 갱신 날짜: 2006/08/21
as07885_